package com.logistics.modules.sys.controller;

import com.logistics.common.utils.R;
import com.logistics.modules.sys.entity.SysUserEntity;
import com.logistics.modules.sys.form.SysLoginForm;
import com.logistics.modules.sys.service.SysLoginService;
import com.logistics.modules.sys.service.SysUserService;
import com.logistics.modules.sys.service.SysUserTokenService;
import lombok.extern.slf4j.Slf4j;
import org.apache.shiro.crypto.hash.Sha256Hash;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import java.io.IOException;
import java.util.Map;


/**
 * 系统登录控制器
 *
 * @author 水穷处云起时
 * @date 2022/05/03
 */
@Slf4j
@RestController
public class SysLoginController extends AbstractController {

	@Autowired
	private SysUserTokenService sysUserTokenService;

	@Autowired
	private SysLoginService sysLoginService;


	/**
	 * 登录
	 */
	@PostMapping("/sys/login")
	public Map<String, Object> login(@RequestBody SysLoginForm form)throws IOException {

		R login = sysLoginService.login(form);

		return login;
	}

	/**
	 * 退出
	 */
	@PostMapping("/sys/logout")
	public R logout() {
		sysUserTokenService.logout(getUserId());
		return R.ok();
	}
	
}
